# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=opencolorio
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=701.a557a85
pkgrel=3
pkgdesc="A color management framework for visual effects and animation (mingw-w64)"
arch=('any')
url="http://opencolorio.org"
license=('BSD')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-tinyxml")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-yaml-cpp"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "git")
options=('strip')
source=("${_realname}"::"git+https://github.com/imageworks/OpenColorIO.git"
        #${_realname}-${pkgver}.tar.gz::https://github.com/imageworks/OpenColorIO/tarball/v${pkgver}.tar.gz
        mingw-w64.patch
        fix-redefinitions.patch
        detect-mingw-python.patch)
sha256sums=('SKIP'
            '8cbe2c85d914944e3314418dae898f031e996e51da20907fe1541186c3a7a91b'
            '125075bf0ed707d609251ee3666f4e2042e9bca870a04e0fb1f7d96dedfd7196'
            '03418284a6c7677bb52125256feccf5c6960444d9968e70abd0e1eb018b19558')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
  patch -p1 -i ${srcdir}/mingw-w64.patch
  patch -p1 -i ${srcdir}/fix-redefinitions.patch
  patch -p1 -i ${srcdir}/detect-mingw-python.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DGLEW_INCLUDES=${MINGW_PREFIX}/include \
    -DGLEW_LIBRARIES=${MINGW_PREFIX}/lib/libglew32.dll.a \
    -DUSE_EXTERNAL_TINYXML=ON \
    -DUSE_EXTERNAL_YAML=ON \
    -DUSE_EXTERNAL_LCMS=ON \
    -DOCIO_USE_BOOST_PTR=ON \
    -DOCIO_BUILD_PYGLUE=ON \
    -DOCIO_PYGLUE_LINK=ON \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python3.exe \
    -DOCIO_BUILD_TRUELIGHT=OFF \
    ../$_realname

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/${_realname}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  cd ${pkgdir}${MINGW_PREFIX}
  mkdir -p bin
  mv lib/*.dll bin/
}
